// pages/time/time.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timeList:[
      {
        text:"关闭",
        checked:true,
        time:0
      },
      {
        text:"10分钟",
        time:600,  
      },
      {
        text: "20分钟",
        time:1200,
      },
      {
        text:"30分钟",
        time:1800,
      },
      {
        text:"1小时",
        time:3600
      },
      {
        text:"自定义",
        time:0
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  onTap:function(e){
    var index=e.currentTarget.dataset.index;
    var time=this.data.timeList[index].time;
    if(time>0){
      setTimeout(() => {
        this.closeApp();
      }, time * 1000);
    }
  },

  closeApp:function(){
    app.globalData.close=true;
    wx.reLaunch({
      url: '../index/index',
    });
  },

  onChange:function(e){
    var time=e.detail.value;
    var timeArr=time.split(":");
    time=parseInt(timeArr[0])*60*60+parseInt(timeArr[1])*60;
    if (time > 0) {
      setTimeout(() => {
        this.closeApp();
      }, time * 1000);
    }
  }
})